/*
    project : M2R PLAN-A
    author : Jason
    date : 2017-8-29
*/
$(function () {

    // home : slider
    if($('#homeSlider').length>0) {
        $('#homeSlider').bxSlider({
            controls:false,
            auto:true,
            autoHover:true
        });
    }

    // product detail : slider
    if($('.product-detail-gallery').length>0) {
        $('.product-detail-gallery .bxslider').bxSlider({
            controls:false,
            pagerCustom: '#bx-pager'
        });
    }
    
    // all : search top
    if($('.search-top').length>0) {
        $(".search-trigger").click(function(){
            $('.search-top').fadeIn();
        });
        $(".search-top-close").click(function(){
            $('.search-top').fadeOut();
        });
    }

    // all : back to top
    if($('.b2t').length>0) {
        var scrollTrigger = 100,
            backToTop = function () {
                var scrollTop = $(window).scrollTop();
                if (scrollTop > scrollTrigger) {
                    $('.b2t').fadeIn();
                } else {
                    $('.b2t').fadeOut();
                }
            };
        backToTop();
        $(window).on('scroll', function () {
            backToTop();
        });
        $('.b2t').on('click', function (e) {
            e.preventDefault();
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        });
    }

    // all : thumbs
    if($('.useThumb').length>0) {
        $('.useThumb img').jqthumb({
            width: '100%',
            height: '100%'
        });
    }

    // all : slickNav
    if($('#menu').length>0) {
        $('#menu').slicknav({
            label:'',
            prependTo:'.header'
        });
    }

});